
package com.joysuch.wwyt.datadump.biz.convertor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import cn.zlg.common.datadump.annotation.DataDumpField;
import cn.zlg.common.datadump.convertor.FieldValueConvert;
import com.joysuch.wwyt.bp.enums.DeviceFacilityTypes;
import com.joysuch.wwyt.bp.service.BpDeviceFacilityCollectionService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ExportFindStorageTankAreaBindMonitorPoints implements FieldValueConvert<Long, String> {

    private static final Logger logger = LoggerFactory.getLogger(ExportFindStorageTankAreaBindMonitorPoints.class);

    @Autowired
    private BpDeviceFacilityCollectionService service;

    @Override
    public String convert(Object bean, Long value, DataDumpField dataField) {
        List<String> codes = service.findDeviceBindedMonitorPointCodes(DeviceFacilityTypes.CHU_GUAN_QU, value);
        return StringUtils.join(codes, "\n");
    }

    @Override
    public boolean supportBatch() {
        return true;
    }

    @Override
    public List<String> convert(List<Object> bean, List<Long> value, DataDumpField dataDumpField) {
        if(value == null || value.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        List<List<String>> list = service.findDeviceBindedMonitorPointCodes(DeviceFacilityTypes.CHU_GUAN_QU,
                value);
        List<String> result = new ArrayList<>(list.size());
        for(List<String> item : list) {
            result.add(StringUtils.join(item, "\n"));
        }
        logger.debug("batch query results: {} -> {} ", value, result);
        return result;
    }
}
